cmake_minimum_required(VERSION 3.25)
project(Visual_Location)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message(STATUS "Eigen include directory: " $ENV{EIGEN_DIR})
include_directories($ENV{EIGEN_DIR})

find_package(OpenCV REQUIRED)
message(STATUS "OpenCV include directory: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV libs: ${OpenCV_LIBS}")
include_directories(${OpenCV_INCLUDE_DIRS})

find_package(glog)
message(STATUS "glog: $ENV{glog_DIR}")
message(STATUS "glog libs: ${glog_LIBRARIES}")
file(TO_CMAKE_PATH "$ENV{glog_DIR}\\include" glog_INCLUDE_DIRS)
message(STATUS "glog headers: ${glog_INCLUDE_DIRS}")
include_directories(${glog_INCLUDE_DIRS} $ENV{glog_DIR})

include_directories("include")

file(GLOB_RECURSE HEADERS "include/*.h")
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE TESTS "tests/*.cpp")
message(STATUS "Header files: ${HEADERS}")
message(STATUS "Source files: ${SOURCES}")
message(STATUS "Test files: ${TESTS}")


set(TARGET_MAIN ON)
set(TARGET_TEST OFF)
set(TEST_VL OFF)

if(${TARGET_MAIN})
    set(TARGET_NAME "visual_location")
    add_definitions(-D_RUNNING_FLAG_MAIN)
    message(STATUS "Compile target ${TARGET_NAME}")
    add_executable(${TARGET_NAME} samples/main.cpp)
    target_sources(${TARGET_NAME} PUBLIC ${HEADERS})
    target_sources(${TARGET_NAME} PUBLIC ${SOURCES})
    target_link_libraries(${TARGET_NAME} ${OpenCV_LIBS})
endif()


if(${TARGET_TEST})
    set(TARGET_NAME "vl_unit_test")
    add_definitions(-D_RUNNING_FLAG_TEST)
    message(STATUS "Compile target ${TARGET_NAME} (unit-test)")
    add_executable(${TARGET_NAME} samples/test.cpp)
endif()

if(${TEST_VL})
    add_definitions(-D_RUNNING_FLAG_GTEST)
    add_subdirectory("tests")
endif()

